//
//  ChatViewController.m
//  DriftDog
//
//  Created by rimi on 15/9/7.
//  Copyright (c) 2015年 廖马林. All rights reserved.
//

#import "ChatViewController.h"
#import "FriendsView.h"
#import "ChatView.h"

@interface ChatViewController ()

@property (nonatomic, strong) UISegmentedControl *segmented;
@property (nonatomic, strong) FriendsView *friendsView;
@property (nonatomic, strong) ChatView *chatView;
@property (nonatomic, strong) UIButton *addFriendButton;
@property (nonatomic, strong) UISearchController *search;

- (void)initializeUserInterface;

@end

@implementation ChatViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self initializeUserInterface];
}

#pragma mark - init

- (void)initializeUserInterface {

    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self addTitleLabelWithName:@"聊天"];
    [self.view addSubview:self.segmented];
    [self.view addSubview:self.chatView];

}

#pragma mark 
#pragma mark - action_onSegmented
- (void)action_onSegmented:(UISegmentedControl *)segmented {
    
    UISegmentedControl *segmentedControl = (UISegmentedControl *)segmented;
    NSArray *view = @[self.chatView, self.friendsView];
    
    [self.view addSubview:view[segmentedControl.selectedSegmentIndex]];
    
    switch (segmented.selectedSegmentIndex) {
        case 0:
        {
            self.chatView.hidden = NO;
            self.friendsView.hidden = YES;

        }
            break;
        case 1:
        {
            
            self.chatView.hidden = YES;
            self.friendsView.hidden = NO;
        }
            break;
        default:
            break;
    }
}

#pragma mark
#pragma mark - getter
- (UISegmentedControl *)segmented {

    if (!_segmented) {
        _segmented = ({
        
            UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:@[@"消息", @"好友"]];
            segmented.frame = DHFlexibleFrame(CGRectMake(0, 0, ORIGIN_WIDTH, 60), YES);
            segmented.center = DHFlexibleCenter(CGPointMake(ORIGIN_WIDTH / 2, NAV_HEIGHT + 30));
            [segmented setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal];
            segmented.selectedSegmentIndex = 0;
            segmented.tintColor = [UIColor brownColor];
            [segmented addTarget:self action:@selector(action_onSegmented:) forControlEvents:UIControlEventValueChanged];
            
            segmented;
        });
    }
    return _segmented;
}
- (FriendsView *)friendsView {

    if (!_friendsView) {

        _friendsView = [[FriendsView alloc] init];
        _friendsView.hidden = YES;
    }
    return _friendsView;
}
- (ChatView *)chatView {

    if (!_chatView) {
        _chatView = [[ChatView alloc] init];
    }
    
    return _chatView;
}

@end
